#include"stdafx.h"
#include "Stack.h"

template<typename T>
Stack<T>::Stack():_size(0), _head(NULL) {}


template<typename T>
bool Stack<T>::isEmpty() const{
	return _size==0;
}

template<typename T>
int Stack<T>::size() const{
	return _size;
}

template<typename T>
void Stack<T>::pop(T& stackTop){
	if (!isEmpty()){
		_size--;
		ListNode* cur;
		stackTop = _head->item;
		cur = _head;
		_head = _head->next;
		delete cur;
		cur = NULL;
	}
}

template<typename T>
void Stack<T>::push(const T& newItem){
	_size++;
	ListNode* newPtr = new ListNode;
	newPtr->item = newItem;
	newPtr->next = _head;
	_head = newPtr;
}

template<typename T>
void Stack<T>::getTop(T& stackTop) const{
	if (!isEmpty())
		stackTop = _head->item;
}	